﻿Public Class Main
    'Lấy thông tin username
    Public NVid As String
    'Kiểm tra đăng nhập 
    Public flag_login As Integer
    Public NVname As String

    Private Sub loadDGV()
        Dim dt As DataTable
        Dim cn As New DatabaseConnect
        dt = New DataTable()
        dt = cn.GetData("SELECT ct.MaNhap[Ma],STT[stt],MaLoai[Loai],soluong[SoLuong],MaNCC[NCC],NULL[KH],ghichu[GhiChu],NULL[ThanhTien],NULL[TongTien] FROM SanPham_Nhap_ChiTiet ct, SanPham_Nhap n Where n.MaNhap = ct.MaNhap and n.ngayNhap = '" + Date.Today + "' union all(SELECT ct.MaXuat[Ma],STT[stt],MaLoai[Loai],soluong[SoLuong],NULL[NCC],MaKH[KH],ghichu[GhiChu],thanhtien[ThanhTien],tongtien[TongTien] FROM SanPham_Xuat_ChiTiet ct, SanPham_Xuat x Where x.MaXuat = ct.MaXuat and x.ngayXuat = '" + Date.Today + "')")
        dgv.DataSource = dt
    End Sub
    Private Sub ĐăngNhậpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐăngNhậpToolStripMenuItem.Click
        Dim dn As New DangNhap()
        dn.ShowDialog()
        If flag_login = 1 Then
            MessageBox.Show(NVname + " đăng nhập thành công!")
            KháchHàngToolStripMenuItem.Visible = True
            NhàCungCấpToolStripMenuItem.Visible = True
            ĐăngXuấtToolStripMenuItem.Visible = True
            ĐăngNhậpToolStripMenuItem.Visible = False
            ĐặtHàngToolStripMenuItem.Enabled = True
            TìnhTrạngToolStripMenuItem.Enabled = True
            TrịGiáToolStripMenuItem.Enabled = True
            ToolStripMenuItem2.Enabled = True
            SP_Nhap1.Enabled = True
            SP_Xuat1.Enabled = True
            btnNhap.Enabled = True
            btnXuat.Enabled = True
            If NVname = "Admin" Then
                ToolStripSeparator2.Visible = True
                NhânViênToolStripMenuItem.Visible = True
            End If
            loadDGV()
        End If
    End Sub

    Private Sub ToànBộToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToànBộToolStripMenuItem.Click
        Dim qlsp As New QL_SanPham()
        qlsp.ShowDialog()
        If flag_login = 1 Then
            KháchHàngToolStripMenuItem.Visible = True
            NhàCungCấpToolStripMenuItem.Visible = True
            ĐăngXuấtToolStripMenuItem.Visible = True
            ĐăngNhậpToolStripMenuItem.Visible = False
            ĐặtHàngToolStripMenuItem.Enabled = True
            TìnhTrạngToolStripMenuItem.Enabled = True
            TrịGiáToolStripMenuItem.Enabled = True
            ToolStripMenuItem2.Enabled = True
            SP_Nhap1.Enabled = True
            SP_Xuat1.Enabled = True
            btnNhap.Enabled = True
            btnXuat.Enabled = True
            If NVname = "Admin" Then
                ToolStripSeparator2.Visible = True
                NhânViênToolStripMenuItem.Visible = True
            End If
        End If
    End Sub

    Private Sub NhậpToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NhậpToolStripMenuItem1.Click
        Dim ct_n As New QL_SP_Nhap()
        ct_n.ShowDialog()
    End Sub

    Private Sub XuấtToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XuấtToolStripMenuItem1.Click
        Dim ct_x As New QL_SP_Xuat()
        ct_x.ShowDialog()
    End Sub

    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        Dim nv As New NV_Nhap()
        nv.ShowDialog()
    End Sub

    Private Sub ĐăngXuấtToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐăngXuấtToolStripMenuItem.Click
        MessageBox.Show(NVid + " đăng xuất thành công!")
        flag_login = 0
        NVid = ""
        NVname = ""
        KháchHàngToolStripMenuItem.Visible = False
        NhàCungCấpToolStripMenuItem.Visible = False
        ĐăngXuấtToolStripMenuItem.Visible = False
        ĐăngNhậpToolStripMenuItem.Visible = True
        ĐặtHàngToolStripMenuItem.Enabled = False
        TìnhTrạngToolStripMenuItem.Enabled = False
        TrịGiáToolStripMenuItem.Enabled = False
        ToolStripMenuItem2.Enabled = False
        SP_Nhap1.Enabled = False
        SP_Xuat1.Enabled = False
        btnNhap.Enabled = False
        btnXuat.Enabled = False
        dgv.Enabled = False
    End Sub

    Private Sub DanhSáchToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DanhSáchToolStripMenuItem1.Click
        Dim dskh As New KH_Danhsach()
        dskh.ShowDialog()
    End Sub

    Private Sub DanhSáchToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DanhSáchToolStripMenuItem2.Click
        Dim dsncc As New NCC_Danhsach()
        dsncc.ShowDialog()
    End Sub

    Private Sub NhânViênToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NhânViênToolStripMenuItem1.Click
        Dim dsnv As New NV_Danhsach()
        dsnv.ShowDialog()
    End Sub

    Private Sub TìnhTrạngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TìnhTrạngToolStripMenuItem.Click
        Dim tt As New SP_TinhTrang()
        tt.ShowDialog()
    End Sub

    Private Sub TrịGiáToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrịGiáToolStripMenuItem.Click
        Dim tg As New SP_TriGia()
        tg.ShowDialog()
    End Sub

    Private Sub HệSốLươngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HệSốLươngToolStripMenuItem.Click
        Dim hsl As New NV_HeSoLuong()
        hsl.ShowDialog()
    End Sub

    Private Sub TrìnhĐọToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrìnhĐọToolStripMenuItem.Click
        Dim td As New NV_TrinhDo()
        td.ShowDialog()
    End Sub

    Private Sub ĐặtHàngToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ĐặtHàngToolStripMenuItem.Click
        Dim dh As New SP_DatHang()
        dh.ShowDialog()
    End Sub

    Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
        Dim lsp As New SP_Loai()
        lsp.ShowDialog()
    End Sub

    Private Sub btnNhap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNhap.Click
        'Lay command ben SP_Nhap
        SP_Nhap1.Nhap(sender, e)
        loadDGV()
    End Sub

    Private Sub btnXuat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXuat.Click
        'Lay command ben SP_Xuat
        SP_Xuat1.Xuat(sender, e)
        loadDGV()
    End Sub
End Class